<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="maximum-scale=1.0, minimum-scale=1.0, user-scalable=0, initial-scale=1.0, width=device-width"/>
<meta name="format-detection" content="telephone=no, email=no, date=no, address=no">
<title>Hello APP</title>
<link rel="stylesheet" type="text/css" href="../../css/aui-flex.css" />
<link rel="stylesheet" type="text/css" href="../../css/aui.css" />
<link rel="stylesheet" type="text/css" href="../../css/common.css" />
<style>
.box{
	padding: 0 1rem;
}
.list{
	color:#333;
	height: 2.4rem;
}
.comFlexItem .tit{
	font-size:0.7rem;
	color:#333;
}
.comFlexItem .del{
	width: 0.4rem;
	height: 0.4rem;
	padding-left: 1rem;
}
.popBox{
	position: fixed;
	z-index: 15;
	bottom: 1rem;
	left: 1rem;
	right: 1rem;
}
.popBtn{
	height: 2.5rem;
	line-height: 2.5rem;
	border: 1px solid #F45771;
	background: #FFFFFF;
	border-radius: 25px;
	text-align: center;
	color:#F45771;
	width: 100%;
	font-size:0.7rem;
	margin-bottom: 0.2rem;
}
.popBtn.clo{
	background: #F45771;
	margin-bottom: 0rem;
	color:#fff;
}
.rig{
	padding-right: 1rem
}
.comFixed{
	position: fixed;
	bottom: 1rem;
	padding: 0 1rem;
	width: 100%;
	text-align: center;
}
.comFixed p{
	font-size:0.5rem;
	color: #9b9b9b;
	padding-bottom: 1rem;
}
</style>
</head>
<body>
<div class="bg-white box">
	<div class="comFlexItem right-arrow aui-border-b" tapmode onclick="openTest()">
		<div class="tit">登录手机号</div>
		<div></div>
		<div class="rig" id="phone"></div>
	</div>
	<div class="comFlexItem right-arrow aui-border-b" tapmode onclick="openWin('address_win')">
		<div class="tit">收货地址</div>
		<div></div>
		<div></div>
	</div>
	<div class="comFlexItem right-arrow aui-border-b" tapmode onclick="openWin('alipay_account_win')">
		<div class="tit">支付宝账号</div>
		<div></div>
		<div class="rig" id="apyPhone"></div>
	</div>
	<div class="comFlexItem right-arrow aui-border-b" tapmode onclick="openWin('about_win')">
		<div class="tit">关于有蜜</div>
		<div></div>
		<div></div>
	</div>
	<div class="comFlexItem right-arrow aui-border-b" tapmode onclick="checkUpdate();">
		<div class="tit">检测更新</div>
		<div></div>
		<div></div>
	</div>
	<div class="comFlexItem aui-border-b aui-flex-between">
		<div class="tit">清除缓存</div>
		<div></div>
		<div tapmode onclick="clearCache()"><span class="aui-font-size-14" id="cache">0</span>M<i class="aui-iconfont aui-icon-trash del"></i></div>
	</div>
</div>
<div class="comFixed">
	<p>有蜜 V2.2.0</p>
	<div class="comBtn" tapmode onClick="logOut()">退出当前账号</div>
</div>
</body>
<script type="text/javascript" src="../../script/import.js"></script>
<script type="text/javascript" src="../../script/common.js"></script>
<script type="text/javascript">
apiready = function(){
	api.parseTapmode();
	getCache()
	if(getUserId()){
		getUserPhone();
	}
	api.addEventListener({
	    name: 'reLoginEvent'
	}, function(ret, err){
	    if( ret ){
				getUserPhone();
	    }
	});
};
//获取用户信息
// function getUserPhone(){
// 	var userInfo = getUserinfo();
// 	if(userInfo && userInfo.user_mobile){
// 		$$('#phone').text(userInfo.user_mobile);
// 	}else{
// 		$$('#phone').text("");
// 	}
// }
function getUserPhone() {
    api.ajax({
        url: BASE_URL + 'App/User/userInfo',
        method: 'post',
        data: {
            values: {
                userid: getUserId()
            }
        }
    }, function(ret, err) {
        if (ret) {
            if (ret.code == 1 && ret.data) {
							// 登录手机号
							var mobile = ret.data.user_mobile;
							var phone = mobile.substr(0, 3) + '****' + mobile.substr(7);
							$$('#phone').text(phone);
							// 支付宝账号
							var apyMobile = ret.data.data_ali_email;
							if(apyMobile){
							var apyPhone = apyMobile.substr(0, 3) + '****' + apyMobile.substr(7);
							$$('#apyPhone').text(apyPhone)
							}
            }
        }
    });
}
// 打开手机验证
function openTest(){
	api.openWin({
	    name: 'test_phone_win',
	    url: 'test_phone_win.html',
	    pageParam: {
	        name: 'test'
	    }
	});

}
//检测缓存
function getCache(){
api.getCacheSize(function(ret) {
	var size = ret.size;
	if(size>0){
		var mb = size/1024/1024;
		var txt = mb.toFixed(2);
		$$('#cache').text(txt);
	}
});
}
//清空缓存
function clearCache(el){
		var confirmMaskTxt = ['缓存会使操作更流畅。是否确认删除缓存？','取消','确认删除'];
		openConfirmMask(confirmMaskTxt,'delCache()');
}
function delCache(){
	api.clearCache(function() {
		toast('清除完成');
		$$('#cache').text('0');
	});
}
//检测更新
function checkUpdate(){
	alert('已经是最新版本');
}

//退出登录
function logOut(){
	api.removePrefs({
      key: 'userId'
     });
	api.removePrefs({
      key: 'userInfo'
     });
	api.removePrefs({
      key: '_CART_DATA_'
     });
	
  	$api.clearStorage();
	toast('退出成功');
	api.sendEvent({
		name: 'logOutEvent'
	});
	
	// setTimeout(function(){
	// 	api.closeWin()
	// },1000);
}
</script>
</html>
